package com.philips.work.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.philips.common.core.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.philips.common.log.annotation.Log;
import com.philips.common.log.enums.BusinessType;
import com.philips.common.security.annotation.RequiresPermissions;
import com.philips.work.domain.YwAccount;
import com.philips.work.service.IYwAccountService;
import com.philips.common.core.web.controller.BaseController;
import com.philips.common.core.web.domain.AjaxResult;
import com.philips.common.core.utils.poi.ExcelUtil;
import com.philips.common.core.web.page.TableDataInfo;

/**
 * 账户管理Controller
 * 
 * @author philips
 * @date 2025-05-19
 */
@RestController
@RequestMapping("/account")
public class YwAccountController extends BaseController
{
    @Autowired
    private IYwAccountService ywAccountService;

    /**
     * 查询账户管理列表
     */
    @RequiresPermissions("work:account:list")
    @GetMapping("/list")
    public TableDataInfo list(YwAccount ywAccount)
    {
        startPage();
        List<YwAccount> list = ywAccountService.selectYwAccountList(ywAccount);
        return getDataTable(list);
    }

    /**
     * 查询所有账户列表
     */
    @GetMapping("/findAllAccountList")
    public AjaxResult findAllAccountList()
    {
        List<YwAccount> list = ywAccountService.findAllAccountList();
        if (StringUtils.isNull(list))
        {
            list = new ArrayList<YwAccount>();
        }
        return success(list);
    }

    /**
     * 导出账户管理列表
     */
    @RequiresPermissions("work:account:export")
    @Log(title = "账户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwAccount ywAccount)
    {
        List<YwAccount> list = ywAccountService.selectYwAccountList(ywAccount);
        ExcelUtil<YwAccount> util = new ExcelUtil<YwAccount>(YwAccount.class);
        util.exportExcel(response, list, "账户管理数据");
    }

    /**
     * 获取账户管理详细信息
     */
    @RequiresPermissions("work:account:query")
    @GetMapping(value = "/{ids}")
    public AjaxResult getInfo(@PathVariable("ids") String ids)
    {
        return success(ywAccountService.selectYwAccountByIds(ids));
    }

    /**
     * 新增账户管理
     */
    @RequiresPermissions("work:account:add")
    @Log(title = "账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwAccount ywAccount)
    {
        return toAjax(ywAccountService.insertYwAccount(ywAccount));
    }

    /**
     * 修改账户管理
     */
    @RequiresPermissions("work:account:edit")
    @Log(title = "账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwAccount ywAccount)
    {
        return toAjax(ywAccountService.updateYwAccount(ywAccount));
    }

    /**
     * 删除账户管理
     */
    @RequiresPermissions("work:account:remove")
    @Log(title = "账户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{idss}")
    public AjaxResult remove(@PathVariable String[] idss)
    {
        return toAjax(ywAccountService.deleteYwAccountByIdss(idss));
    }
}
